
<form>
    <!-- This mock form is here due to IE and/or jQuery form plug-in bug. When form is inserted after ajaxSubmit dynamically, IE erases it. -->
    <input type="submit" style="display:none">
</form>

<form enctype="multipart/form-data" action="upload.php" method="POST" class="uploadform">
<input type="hidden" name="form_sent">
<table cellspacing=0 style="width:100%;margin-top: 4px;margin-bottom: 1px;">
    <tr>
        <td>
    <div class="ui-state-highlight ui-corner-top open2" style="float:right;margin-left:2px;margin-right:4px">
     <span class="ui-icon ui-icon-document-b" style="float:left"></span>Supplements&nbsp;
    </div>
    <div class="ui-state-highlight ui-corner-top open3" style="float:right;margin-left:2px">
        <span class="ui-icon ui-icon-tag" style="float:left"></span>Categories&nbsp;
    </div>
    <div class="ui-state-highlight ui-corner-top open1" style="float:right">
        <span class="ui-icon ui-icon-document" style="float:left"></span>Metadata&nbsp;
    </div>
        <b>&nbsp;Add new record</b>
        </td>
    </tr>
</table>

<table cellspacing="0" style="width:100%;border-top: solid 1px #D5D6D8" class="test">
<tr>
    <td class="threedleft">
    <?php 
        //Dragan M. Change the name of the button from Save to Fetch
	if(empty($document_exists)){ ?>
		<input type="hidden" name="fetch">
	<?php }else{ ?>
		<input type="hidden" name="save">
	<?php } ?>
    <?php $document_exists = $document->getMetadata()->getTitle();?>
        <button class="uploadsave"
        value="test">
		<?php 
        //Dragan M. Change the name of the button from Save to Fetch
		if(empty($document_exists)){
			echo "Fetch";
		}else{
			echo "Save";
		}
		?>
		</button>
    </td>
    <td class="threedright">
        <table cellspacing=0>
            <tr>
                <td class="select_span" style="line-height:22px;width:10em">
                    <input type="checkbox" checked class="uploadcheckbox" style="display:none" name="shelf">
                    <span class="ui-icon ui-icon-check" style="float:left;margin-top: 2px">
                    </span>Add to Shelf
                </td>
                <td class="select_span" style="line-height:22px;width:11em">
                    <input type="checkbox" class="uploadcheckbox" style="display:none" name="clipboard">
                    <span class="ui-icon ui-icon-close" style="float:left;margin-top: 2px">
                    </span>Add to Clipboard
                </td>
                <td class="select_span" style="line-height:22px;width: 10em;text-align:right">
                    <input type="checkbox" class="uploadcheckbox" style="display:none" name="project">
                    <div style="float:right">Add&nbsp;to&nbsp;Project&nbsp;</div>
                    <span class="ui-icon ui-icon-close" style="float:right;margin-top: 2px">
                    </span>
                </td>
                <td style="line-height:22px;width: 18em">
                    <select name="projectID" style="width:200px">
                    <?php
                    foreach($projects as $project) {
                        print '<option value="'.$project->getId().'">'.htmlspecialchars($project->getProject()).'</option>'.PHP_EOL;
                    }
                    ?>
                    </select>
                </td>
            </tr>
        </table>
</td>
</tr>
<tr>
<td class="threedleft">
Paper rating:
</td>
<td class="threedright">
    <table cellspacing=0>
        <tr>
            <td class="select_span" style="line-height:16px;width:6em">
                <input type="radio" class="uploadcheckbox" style="display:none" name="rating" value="1">
                <span class="ui-icon ui-icon-radio-on" style="float:left">
                </span>Low
            </td>
            <td class="select_span" style="line-height:16px;width:8em">
                <input type="radio" checked class="uploadcheckbox" style="display:none" name="rating" value="2">
                <span class="ui-icon ui-icon-radio-off" style="float:left">
                </span>Medium
            </td>
            <td class="select_span" style="line-height:16px;width:6em">
                <input type="radio" class="uploadcheckbox" style="display:none" name="rating" value="3">
                <span class="ui-icon ui-icon-radio-on" style="float:left">
                </span>High
            </td>
        </tr>
    </table>
</td>
</tr>
</table>


<table cellspacing="0" style="width:100%" class="table1">
<tr>
<td class="threedleft">
<b>Local PDF file:</b>
</td>
<td class="threedright">
<?php
if (!empty($tempfile)) {

	print "<input type=\"hidden\" name=\"filename\" value=\"$tempfile\">";
    if (!isset($_SESSION['pdfviewer']) || (isset($_SESSION['pdfviewer']) && $_SESSION['pdfviewer'] == 'external'))
	print "<iframe class=\"pdf-file\" src=\"temp.php?tempfile=$tempfile#pagemode=none&scrollbar=1&page=1&navpanes=0&toolbar=0&statusbar=0&view=FitH,20\" style=\"display:block;width:99%;height:300px;border:1px inset #afaea9\"></iframe>";
    if (isset($_SESSION['pdfviewer']) && $_SESSION['pdfviewer'] == 'internal')
	print "<iframe class=\"pdf-file\" src=\"viewpdf.php?file=$tempfile&page=1&navpanes=0&toolbar=0\" style=\"display:block;width:99%;height:300px;border:1px inset #a5a6a9\"></iframe>";

} else {
	print '<input type="file" name="form_new_file">';
}
?>
</td>
</tr>
<?php
if (empty($tempfile)) {
?>
<tr>
<td class="threedleft">
<b>PDF from the Web:</b>
</td>
<td class="threedright">
<input type="text" name="form_new_file_link" value="<?php 
	$url = $document->getFile()->getUrl();
	if(isset($url) && $url!="")
		echo $url;
//if (!empty($web_pdf)) print $web_pdf; ?>" size="85" style="width:99%">
</td>
</tr>
<?php
}
?>
<?php
$uid = $document->getUid();
if(isset($uid) && !empty($uid) && $uid!="")
	$paper_uids = explode("|", $uid);
if (!empty($paper_uids)) {
	foreach($paper_uids as $paper_uid) {
?>
<tr>
<td class="threedleft">
<b>Database UID:</b>
</td>
<td class="threedright">
 <input type="text" size="80" name="uid[]" style="width: 99%" value="<?php print htmlspecialchars($paper_uid) ?>">
</td>
</tr>
<?php
	}
}
?>
<tr>
<td class="threedleft">
<b>DOI:</b>
</td>
<td class="threedright">
 <input type="text" size="80" name="doi" style="width:99%" value="<?php echo htmlspecialchars($document->getMetadata()->getDoi());
 //print isset($document->getMetadata()->getDoi()) ? htmlspecialchars($document->getMetadata()->getDoi()) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
<b>Database UID:</b>
<div class="adduidrow" style="float:right;cursor:pointer">+</div>
</td>
<td class="threedright">
 <input type="text" size="80" name="uid[]" style="width:99%" value=""
  title="<b>Examples:</b><br>PMID:123456<br>PMCID:123456<br>NASAADS:123456<br>ARXIV:123456<br>JSTOR:123456<br>ACM:123456<br>IEEE:12345">
</td>
</tr>
<tr>
<td class="threedleft">
Title:
</td>
<td class="threedright">

<textarea name="title" cols=80 rows=2 wrap="soft" style="width:99%">
<?php echo htmlspecialchars($document->getMetadata()->getTitle());// echo isset($document->getMetadata()->getTitle()) ? htmlspecialchars($document->getMetadata()->getTitle()) : '' ?>
</textarea>
</td>
</tr>
<tr>
<td class="threedleft">
Authors:
</td>
<td class="threedright">
<textarea cols="80" rows="2" name="authors" style="width:99%" title="Use Medline format:<br>Smith JP, Gupta S">
<?php echo htmlspecialchars($document->getMetadata()->getAuthors());//echo isset($_POST['authors']) ? htmlspecialchars($_POST['authors']) : ''; ?>
</textarea>
</td>
</tr>
<tr>
<td class="threedleft">
Affiliation:
</td>
<td class="threedright">
<textarea cols="80" rows="2" name="affiliation" style="width:99%">
<?php 
	echo htmlspecialchars($document->getMetadata()->getAffiliation());  //echo isset($_POST['affiliation']) ? htmlspecialchars($_POST['affiliation']) : ''; 
?>
</textarea>
</td>
</tr>
<tr>
<td class="threedleft">
Journal abbreviation:
</td>
<td class="threedright">
<input type="text" size="80" name="journal_abbr" style="width:99%" value="<?php echo htmlspecialchars($document->getMetadata()->getJournal());//print isset($_POST['journal_abbr']) ? htmlspecialchars($_POST['journal_abbr']) : '' ?>">
<br>
<select name="journal_abbr2" style="width:99%">
<option value=""></option>
<?php
	foreach($allJournals as $d){
		if(strlen($d->getMetadata()->getJournal())>0)
			print "<option value=\"".htmlspecialchars($d->getMetadata()->getJournal())."\">".htmlspecialchars(substr($d->getMetadata()->getJournal(),0,80))."</option>\r\n";
	}
?>
</select>
</td>
</tr>
<tr>
<td class="threedleft">
Secondary title:
</td>
<td class="threedright">
<input type="text" size="80" name="secondary_title" style="width:99%" value="<?php echo htmlspecialchars($document->getMetadata()->getSecondaryTitle()); //print isset($_POST['secondary_title']) ? htmlspecialchars($_POST['secondary_title']) : '' ?>">
<br>

<select name="secondary_title2" style="width:99%">
<option value=""></option>
<?php
foreach($allSecondaryTitles as $ast){
	if(strlen($ast->getMetadata()->getSecondaryTitle())>0)
		print "<option value=\"".htmlspecialchars($ast->getMetadata()->getSecondaryTitle())."\">".htmlspecialchars(substr($ast->getMetadata()->getSecondaryTitle(),0,80))."</option>\r\n";
}


?>
</select>
</td>
</tr>
<tr>
<td class="threedleft">
Publication date:
</td>
<td class="threedright">
<input type="text" size="10" maxlength="10" name="year" value="<?php echo htmlspecialchars($document->getMetadata()->getYear()); //echo isset($_POST['year']) ? htmlspecialchars($_POST['year']) : '' ?>"> YYYY-MM-DD
</td>
</tr>
<tr>
<td class="threedleft">
Volume:
</td>
<td class="threedright">
<input type="text" size="10" name="volume" value="<?php echo htmlspecialchars($document->getMetadata()->getVolume());//echo isset($_POST['volume']) ? htmlspecialchars($_POST['volume']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Issue:
</td>
<td class="threedright">
<input type="text" size="10" name="issue" value="<?php echo htmlspecialchars($document->getMetadata()->getIssue()); //echo isset($_POST['issue']) ? htmlspecialchars($_POST['issue']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Pages:
</td>
<td class="threedright">
<input type="text" size="10" name="pages" value="<?php echo htmlspecialchars($document->getMetadata()->getPages());//echo isset($_POST['pages']) ? htmlspecialchars($_POST['pages']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Abstract:
</td>
<td class="threedright">
<textarea name="abstract" cols=80 rows=5 wrap="soft" style="width:99%">
<?php echo htmlspecialchars($document->getMetadata()->getAbstract());//isset($_POST["abstract"]) ? htmlspecialchars($_POST['abstract']) : '' ?>
</textarea>
</td>
</tr>
<tr>
<td class="threedleft">
Editor:
</td>
<td class="threedright">
<input type="text" size="80" name="editor" style="width:99%" value="<?php echo htmlspecialchars($document->getMetadata()->getEditor()); //echo isset($_POST['editor']) ? htmlspecialchars($_POST['editor']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Publisher:
</td>
<td class="threedright">
<input type="text" size="80" name="publisher" style="width:99%" value="<?php echo htmlspecialchars($document->getMetadata()->getPublisher());//echo isset($_POST['publisher']) ? htmlspecialchars($_POST['publisher']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Place published:
</td>
<td class="threedright">
<input type="text" size="80" name="place_published" style="width:99%" value="<?php echo htmlspecialchars($document->getMetadata()->getPlacePublished());//echo isset($_POST['place_published']) ? htmlspecialchars($_POST['place_published']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Keywords:
</td>
<td class="threedright">
<div style="float:left; width:50%;">
	<?php 
	$keywords_exists = $document->getMetadata()->getKeywords();
	//var_dump($keywords_exists);
	if(sizeof($keywords_exists)>0){
		print '<table width="100%">';
		$i=0;
		foreach($keywords_exists as $kwd){
			if($i%2==0){
				print '<tr collspan="2">';
			}
			print '<td><input type="checkbox" checked="checked" name="keywords[]" value="'.$kwd->getKeyword().'" />'.$kwd->getKeyword().'</td>';
			if($i%2!=0){
				print '</tr>';
			}
			$i++;
		}
		print '</table>';
		
	}
	?>	
</div>
<div>
	<div <?php $key_size=sizeof($keywords_exists); $size=($key_size*10)-10; if($key_size > 0) echo 'style="float: left;"'; else echo 'style="width: 100%"'; ?>>
	Additional Keywords:
	</div>
	<textarea name="keywords2" rows=2 wrap="soft" <?php $key_size=sizeof($keywords_exists); $size=($key_size*10)-30; if($key_size > 0) echo 'style="width: 49%; float: left; height: '.$size.'px; min-height: 25px; "'; else echo 'style="width: 100%"'; ?> title="Reserved for keywords provided by internet databases. For your custom keywords use Categories.<br>Separator: space, forward slash, space &quot; / &quot;"></textarea>
</div>
</td>
</tr>
<tr>
<td class="threedleft">
Keyword separator:
</td>
<td class="threedright">
<select name="keyword_separator">
    <option> / </option>
    <option>;</option>
    <option>,</option>
</select>
</td>
</tr>
<?php
//Check this again, for multiple URLS
$url = $document->getMetadata()->getUrl();
if(isset($url))
	$paper_urls = explode("|", $url);
if (!empty($paper_urls)) {
	foreach($paper_urls as $paper_url) {
	
?>
<tr>
<td class="threedleft">
URL:
</td>
<td class="threedright">
 <input type="text" size="80" name="url[]" style="width: 99%" value="<?php print htmlspecialchars($paper_url) ?>">
</td>
</tr>
<?php
	}
}
?>
<tr>
<td class="threedleft">
URL:
<div class="addurlrow" style="float:right;cursor:pointer">+</div>
</td>
<td class="threedright">
 <input type="text" size="80" name="url[]" style="width:99%" value="">
</td>
</tr>
<tr>
<td class="threedleft">
Publication type:
</td>
<td class="threedright">
 <input type="text" size="80" name="reference_type" style="width:99%" value="<?php echo htmlspecialchars($document->getMetadata()->getReferenceType()); //print isset($_POST['reference_type']) ? htmlspecialchars($_POST['reference_type']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Custom 1:
</td>
<td class="threedright">
 <input type="text" size="80" name="custom1" style="width: 99%" value="<?php htmlspecialchars($document->getMetadata()->getCustom1());//print isset($_POST['custom1']) ? htmlspecialchars($_POST['custom1']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Custom 2:
</td>
<td class="threedright">
 <input type="text" size="80" name="custom2" style="width: 99%" value="<?php htmlspecialchars($document->getMetadata()->getCustom2());//print isset($_POST['custom2']) ? htmlspecialchars($_POST['custom2']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Custom 3:
</td>
<td class="threedright">
 <input type="text" size="80" name="custom3" style="width: 99%" value="<?php htmlspecialchars($document->getMetadata()->getCustom3());//print isset($_POST['custom3']) ? htmlspecialchars($_POST['custom3']) : '' ?>">
</td>
</tr>
<tr>
<td class="threedleft">
Custom 4:
</td>
<td class="threedright">
 <input type="text" size="80" name="custom4" style="width: 99%" value="<?php htmlspecialchars($document->getMetadata()->getCustom1());//print isset($_POST['custom4']) ? htmlspecialchars($_POST['custom4']) : '' ?>">
</td>
</tr>
</table>
<table cellspacing="0" style="width:100%;display:none" class="table2">
<tr>
<td class="threedleft">
    Add&nbsp;supplementary files:
</td>
<td class="threedright">
<input type="file" name="form_supplementary_file1"><br>
<input type="file" name="form_supplementary_file2"><br>
<input type="file" name="form_supplementary_file3"><br>
<input type="file" name="form_supplementary_file4"><br>
<input type="file" name="form_supplementary_file5">
</td>
</tr>
</table>
<table cellspacing="0" style="width:100%;display:none" class="table3">
<tr>
<td class="threedleft">
Choose&nbsp;category:<br>
</td>
<td class="threedright">
<div class="categorydiv" style="width: 99%;overflow:scroll; height: 400px;background-color: white;color: black;border: 1px solid #C5C6C9">
<table cellspacing=0 style="float:left;width: 49%">
<?php
	

$i=1;
$isdiv = null;
foreach ($allCategories as $cat){
	if ($i > (1+$numberOfCategories['num']/2) && !$isdiv) {
		print '</table><table cellspacing=0 style="width: 49%;float: right;padding:2px">';
		$isdiv = true;
	}
	
	print PHP_EOL.'<tr><td class="select_span">';
	print "<input type=\"checkbox\" name=\"category[]\" value=\"".htmlspecialchars($cat->getId())."\"";
	print " style=\"display:none\"><span class=\"ui-icon ui-icon-close\" style=\"float:left\"></span>".htmlspecialchars($cat->getCategory())."</td></tr>";
	$i=$i+1;
}

?>
</table>
</div>
<span class="ui-icon ui-icon-triangle-1-s enlargelist" style="cursor: pointer;float:left"></span>
<span class="ui-icon ui-icon-triangle-1-n shrinklist" style="cursor: pointer"></span>
<div class="suggestions" style="width: 574px">
<?php
if  (!empty($_POST['title'])) {
    $cat_all = array_unique($cat_all);
    while (list($key,$value) = each($cat_all)) {
            if(stristr("$_POST[title] $_POST[abstract]", $value)) $suggested_categories[] = "<span style=\"cursor: pointer\">$value</span>";
    }
    if (!empty($suggested_categories)) print 'Suggestions: '.implode (", ", $suggested_categories);
}
?>
</div>
</td>
</tr>
<tr>
<td class="threedleft">
Add to new categories:
</td>
<td class="threedright">
<input type="text" size="30" name="category2[]" value=""><br>
<input type="text" size="30" name="category2[]" value=""><br>
<input type="text" size="30" name="category2[]" value="">
</td>
</tr>
</table>
</form>

